package net.scratch.netty.net;

import java.net.InetSocketAddress;

import net.scratch.netty.log.Logger;

import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelHandler;

/**
 * @author Sir Tom
 * 
 */
public class TCPManager implements Runnable, ChannelHandler {

	private static ServerBootstrap strap;
	private static TCPManager world;
	private static int WORLD_PORT = 43594;

	@Override
	public void run() {
		try {
			while (true) {
				strap.setPipelineFactory(new ServerPipelineFactory());
				strap.setOption("child.keepAlive", true);
				strap.setOption("child.tcpNoDelay", true);
				strap.bind(new InetSocketAddress(WORLD_PORT));
				Logger.print("Server alive on [" + WORLD_PORT + "]");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static TCPManager getWorld() {
		return world;
	}

}